﻿<%--<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<CRM.Models.TrainingsCourses>>" %>--%>
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<List<CRM.Database.Model.TrainingsCourses>>" %>
<%@ Import Namespace="CRM.Resourses" %>

<%
    Html.DevExpress().GridView(settings =>
                                   {
                                       settings.Name = "gdTrainingsCourseses";
                                       settings.KeyFieldName = "IdTrainingsCourse";
                                       settings.Width = Unit.Percentage(100);
                                       settings.SettingsPager.PageSize = 20;
                                       settings.CommandColumn.Visible = false;
                                       settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
                                       settings.Settings.ShowFilterRow = true;
                                       settings.CallbackRouteValues = new { Controller = "TC", Action = "TrainingsCoursesListPartial" };
                                       
                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = " ";
                                           column.FieldName = "IdTrainingsCourse";
                                           column.ColumnType = MVCxGridViewColumnType.HyperLink;
                                           column.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
                                           HyperLinkProperties properties = column.PropertiesEdit as HyperLinkProperties;
                                           String urlFormatString = Url.Action("TrainingsCoursesEdit", "TC", new RouteValueDictionary(new { idTrainingsCourse = "{0}"}));
                                           properties.NavigateUrlFormatString = HttpUtility.UrlDecode(urlFormatString);
                                           properties.TextField = "Name";
                                       });
                                       
                                       settings.Columns.Add(column =>
                                       {
                                           column.FieldName = "IdRubric";
                                           column.Caption = Resourses.TrainingsRubric;
                                           column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                           var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                           if (comboBoxProperties != null)
                                           {
                                               var rubricsCol = new CRM.Database.Model.RubricsCollection();
                                               comboBoxProperties.DataSource = rubricsCol.RubricsList;
                                               //comboBoxProperties.DataSource = DB.GetLocalizedRubricsNames(Thread.CurrentThread.CurrentCulture.ToString());
                                               comboBoxProperties.TextField = "LocalizedName";
                                               //comboBoxProperties.TextField = "LocaLizedString";
                                               comboBoxProperties.ValueField = "IdRubric";
                                               //comboBoxProperties.ValueField = "Id";
                                               comboBoxProperties.ValueType = typeof(int);
                                           }
                                       });

                                       settings.Columns.Add(column =>
                                       {
                                           column.ColumnType = MVCxGridViewColumnType.HyperLink;
                                           column.Caption = Resourses.TrainingsLinkToMaterial;
                                           column.FieldName = "LinkToMaterial";
                                           var properties = column.PropertiesEdit as HyperLinkProperties;
                                           if(properties!= null)
                                           {
                                               properties.Text = Resourses.TrainingsLinkToMaterial; ;
                                           }
                                       });

                                       settings.Columns.Add(column =>
                                       {
                                           column.ColumnType = MVCxGridViewColumnType.HyperLink;
                                           column.Caption = Resourses.TrainingsLinkToProgramm;
                                           column.FieldName = "LinkToProgramm";
                                           var properties = column.PropertiesEdit as HyperLinkProperties;
                                           if (properties != null)
                                           {
                                               properties.Text = Resourses.TrainingsLinkToProgramm; ;
                                           }
                                       });

                                       settings.Columns.Add(column =>
                                       {
                                           column.ColumnType = MVCxGridViewColumnType.HyperLink;
                                           column.Caption = Resourses.TrainingsLinkToFeedBack;
                                           column.FieldName = "LinkToFeedBack";
                                           var properties = column.PropertiesEdit as HyperLinkProperties;
                                           if (properties != null)
                                           {
                                               properties.Text = Resourses.TrainingsLinkToFeedBack; ;
                                           }
                                       });
                                       
                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.TrainingsDescription;
                                           column.FieldName = "Description";
                                       });

                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.TrainingsDuration;
                                           column.FieldName = "Duration";
                                       });

                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.TrainingsParticipantCount;
                                           column.FieldName = "ParticipantCount";
                                       });

                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.TrainingsTrainersList;
                                           column.FieldName = "TrainersColumn";
                                           column.ColumnType = MVCxGridViewColumnType.Memo;
                                       });

                                       

                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.TrainingsAudtoriumsList;
                                           column.FieldName = "AuditoriumsColumn";
                                           column.ColumnType = MVCxGridViewColumnType.Memo;
                                       });

                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.TrainingsPlaces;
                                           column.FieldName = "PlacesColumn";
                                           column.ColumnType = MVCxGridViewColumnType.Memo;
                                       });

                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.TrainingCoursesTypes;
                                           column.FieldName = "CourseTypesColumn";
                                           column.ColumnType = MVCxGridViewColumnType.Memo;
                                       });

                                       //settings.Columns.Add(column =>
                                       //{
                                       //    column.FieldName = "IdTrainingCoursesType";
                                       //    column.Caption = Resourses.TrainingCoursesType;
                                       //    column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                       //    var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                       //    if (comboBoxProperties != null)
                                       //    {
                                       //        comboBoxProperties.DataSource = DB.GetLocalizedTrainingCoursesTypesNames(Thread.CurrentThread.CurrentCulture.ToString());
                                       //        comboBoxProperties.TextField = "LocaLizedString";
                                       //        comboBoxProperties.ValueField = "Id";
                                       //        comboBoxProperties.ValueType = typeof(int);
                                       //    }
                                       //});

                                       settings.Columns.Add(column =>
                                       {
                                           column.Caption = Resourses.IsActive;
                                           column.FieldName = "IsActive";
                                           column.ColumnType = MVCxGridViewColumnType.CheckBox;
                                       });


                                       settings.PreRender = (sender, e) =>
                                       {
                                           MVCxGridView gridView = sender as MVCxGridView;
                                           if (gridView != null)
                                               gridView.FilterExpression = "IsActive == true";
                                       };

                                       //settings.Columns.Add(column =>
                                       //{
                                       //    column.Caption = "временное" + Environment.NewLine + " поле";
                                       //    column.SetDataItemTemplateContent(c =>
                                       //    {
                                       //        ViewContext.Writer.Write(
                                       //            //Html.ActionLink("Изменить", "TrainingsCoursesEdit", new { idTrainingsCourse = DataBinder.Eval(c.DataItem, "IdTrainingsCourse") }) + "&nbsp;" +
                                       //            Html.ActionLink("Удалить", "TrainingsCoursesDelete", new { idTrainingsCourse = DataBinder.Eval(c.DataItem, "IdTrainingsCourse") },
                                       //                new { onclick = "return confirm('Удалить учебный курс?')" })
                                       //        );
                                       //    });
                                       //    //column.SetHeaderTemplateContent(c =>
                                       //    //{
                                       //    //    ViewContext.Writer.Write(
                                       //    //        Html.ActionLink("Создать новый курс", "TrainingsCoursesEdit", new { idTrainingsCourse = -1 }).ToHtmlString());
                                       //    //});
                                       //    column.Settings.AllowDragDrop = DefaultBoolean.False;
                                       //    column.Settings.AllowSort = DefaultBoolean.False;
                                       //    column.Width = 70;
                                       //});
                                       
                                   }).Bind(Model).GetHtml();    
%>